{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000\n"
     ]
    }
   ],
   "source": [
    "class WestTeam(object): \n",
    "    \n",
    "    def __init__(self,name):\n",
    "        self.name = name\n",
    "        self.blood = 1000\n",
    "        \n",
    "    def Weapon(self,Weapon_name,num_1):\n",
    "        return num_1\n",
    "        \n",
    "    def defense(self,num_2):\n",
    "        return num_2 * 0.01\n",
    "        \n",
    "    def skill(self,num_3):\n",
    "        return num_3\n",
    "    \n",
    "class MonsterTeam(object): \n",
    "    \n",
    "    def __init__(self,name):\n",
    "        self.name = name\n",
    "        self.blood = 750\n",
    "        \n",
    "    def Weapon(self,Weapon_name,num_1):\n",
    "        return num_1\n",
    "        \n",
    "    def defense(self,num_2):\n",
    "        return num_2 * 0.01\n",
    "        \n",
    "    def skill(self,num_3):\n",
    "        return num_3\n",
    "\n",
    "wukong = WestTeam('wukong')\n",
    "name = 'wukong'\n",
    "print(eval(name).blood)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "wukong = WestTeam('wukong')\n",
    "bajie = WestTeam('bajie')\n",
    "wujing = WestTeam('wujing')\n",
    "wukong.blood,bajie.blood,wujing.blood = 1000,700,700\n",
    "\n",
    "lion = MonsterTeam('lion')\n",
    "elephant = MonsterTeam('elephant')\n",
    "bird = MonsterTeam('bird')\n",
    "\n",
    "def who_fight(name):\n",
    "    if name == 'wukong':            \n",
    "        hit,defense,hit_all = wukong.Weapon('金箍棒',150),wukong.defense(20),wukong.skill(150)\n",
    "    elif name == 'bajie':    \n",
    "        hit,defense,hit_all = bajie.Weapon('九齿钉耙',100),bajie.defense(10),bajie.skill(100)\n",
    "    elif name == 'wujing':      \n",
    "        hit,defense,hit_all = wujing.Weapon('降妖宝杖',100),wujing.defense(10),wujing.skill(100)  \n",
    "    return hit,defense,hit_all\n",
    "\n",
    "def who_fight2(name):\n",
    "    if name == 'lion':\n",
    "        hit,defense,hit_all = lion.Weapon('大金刀',100),lion.defense(15),lion.skill(100)\n",
    "    elif name == 'elephant':\n",
    "        hit,defense,hit_all = elephant.Weapon('大铁杵',100),elephant.defense(15),elephant.skill(100)\n",
    "    elif name == 'bird':\n",
    "        hit,defense,hit_all = bird.Weapon('大长枪',100),bird.defense(15),bird.skill(100) \n",
    "    return hit,defense,hit_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量622.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大鹏精对八戒发动了攻击，八戒剩余血量610.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量495.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "狮子精对悟净发动了攻击，悟净剩余血量610.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量367.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "狮子精对八戒发动了攻击，八戒剩余血量520.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量240.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟空发动了攻击，悟空剩余血量920.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量112.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟空发动了攻击，悟空剩余血量840.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "悟空对狮子精发动了攻击，狮子精剩余血量-15.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大鹏精对悟空发动了攻击，悟空剩余血量760.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,lion\n",
      "lion的血量已清零，请换其他对象攻击\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量622.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟净发动了攻击，悟净剩余血量520.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量495.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "lion的血量已清零，无法继续攻击，重新有你开始\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量367.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对八戒发动了攻击，八戒剩余血量430.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量240.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大鹏精对八戒发动了攻击，八戒剩余血量340.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量112.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大鹏精对八戒发动了攻击，八戒剩余血量250.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "悟空对大鹏精发动了攻击，大鹏精剩余血量-15.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟空发动了攻击，悟空剩余血量680.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,bird\n",
      "bird的血量已清零，请换其他对象攻击\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量622.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "bird的血量已清零，无法继续攻击，重新有你开始\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量495.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟净发动了攻击，悟净剩余血量430.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量367.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对八戒发动了攻击，八戒剩余血量160.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量240.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对八戒发动了攻击，八戒剩余血量70.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量112.5\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对悟净发动了攻击，悟净剩余血量340.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "悟空对大象精发动了攻击，大象精剩余血量-15.0\n",
      "\n",
      "你已完成一次攻击，对方正准备对你发动攻击\n",
      "大象精对八戒发动了攻击，八戒剩余血量-20.0\n",
      "\n",
      "请输入攻击者和攻击对象,用“,”隔开:wukong,elephant\n",
      "取经小队成功打败妖精队，可以继续西行\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    name_list1 = ['wukong','bajie','wujing']\n",
    "    name_dict1 = {'wukong':'悟空','bajie':'八戒','wujing':'悟净'}\n",
    "        \n",
    "    name_list2 = ['lion','elephant','bird']\n",
    "    name_dict2 = {'lion':'狮子精','elephant':'大象精','bird':'大鹏精'}\n",
    "    while True:\n",
    "        fight_name = input('请输入攻击者和攻击对象,用“,”隔开:').split(',')\n",
    "        if eval(fight_name[1]).blood < 0:\n",
    "            eval(fight_name[1]).blood = 0\n",
    "        if eval(fight_name[0]).blood < 0:\n",
    "            eval(fight_name[0]).blood = 0\n",
    "            \n",
    "        if lion.blood + elephant.blood + bird.blood == 0:\n",
    "            print('取经小队成功打败妖精队，可以继续西行')\n",
    "            break\n",
    "        elif wukong.blood + bajie.blood + wujing.blood == 0:\n",
    "            print('取经小队被妖精打败，没有救出师傅，只能另寻他法')\n",
    "            break\n",
    "        \n",
    "        hit,*d,hit_all = who_fight(fight_name[0])\n",
    "        defense = who_fight2(fight_name[1])[1]\n",
    "        if eval(fight_name[1]).blood == 0:\n",
    "            print(f'{fight_name[1]}的血量已清零，请换其他对象攻击\\n')\n",
    "            continue\n",
    "        if eval(fight_name[0]).blood == 0:\n",
    "            print(f'{fight_name[0]}的血量已清零，没法继续战斗，请更换选手\\n')\n",
    "            continue    \n",
    "        eval(fight_name[1]).blood -= (1 - defense) * hit\n",
    "        print(f'{name_dict1[fight_name[0]]}对{name_dict2[fight_name[1]]}发动了攻击，{name_dict2[fight_name[1]]}剩余血量{eval(fight_name[1]).blood}\\n')\n",
    "\n",
    "        \n",
    "        print('你已完成一次攻击，对方正准备对你发动攻击')\n",
    "        fight_name1 = random.choice(name_list1)\n",
    "        fight_name2 = random.choice(name_list2)\n",
    "        \n",
    "        hit,*d,hit_all = who_fight2(fight_name2)\n",
    "        defense = who_fight(fight_name1)[1]\n",
    "        if eval(fight_name2).blood == 0:\n",
    "            print(f'{fight_name2}的血量已清零，无法继续攻击，重新有你开始\\n')\n",
    "            name_list2.remove(fight_name2)\n",
    "            continue\n",
    "        if eval(fight_name1).blood == 0:\n",
    "            print(f'{fight_name1}的血量已清零，等你更换选手上场\\n')\n",
    "            name_list1.remove(fight_name1)\n",
    "            continue    \n",
    "        eval(fight_name1).blood -= (1 - defense) * hit\n",
    "        print(f'{name_dict2[fight_name2]}对{name_dict1[fight_name1]}发动了攻击，{name_dict1[fight_name1]}剩余血量{eval(fight_name1).blood}\\n')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
